export class Storage {
  private static TOKEN = "token";

  // 将token存入storage,根据用户是否选中'自动登录'来存入不同的storage
  static setToken(token: string, remember: boolean): boolean {
    if (token == null) {
      return false;
    }
    remember ? localStorage.setItem(Storage.TOKEN, token) : sessionStorage.setItem(Storage.TOKEN, token);
    return true;
  }

  // 从storage中取出token
  static getToken() {
    let token = localStorage.getItem(Storage.TOKEN);
    if (token == null) {
      token = sessionStorage.getItem(Storage.TOKEN);
    }
    console.log("token", token);
    return token ? token : "";
  }

  // 移除Token
  static removeToken() {
    localStorage.removeItem(Storage.TOKEN);
    sessionStorage.removeItem(Storage.TOKEN);
  }
}
